package com.sky.controller.admin;


import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/admin/category")
@RestController
@Api(tags = "分类接口")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @PutMapping
    @ApiOperation("修改分类")
    public Result update(@RequestBody CategoryDTO categoryDTO) {
        categoryService.updateCategoryInfo(categoryDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("分页")
    public Result<PageResult> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO) {
        PageResult pageResult = categoryService.pageQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    @PostMapping("/status/{status}")
    @ApiOperation("禁用-启用")
    public Result stopAndStar(@PathVariable Integer status, @RequestParam Integer id) {
        System.out.println(status);
        System.out.println(id);
        categoryService.stopAndStar(status, id);
        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("删除分类")
    public Result removeCategeory(Integer id) {
        categoryService.removeCategory(id);
        return Result.success();
    }

    @PostMapping
    @ApiOperation("新增分类")
    public Result addCategory(@RequestBody CategoryDTO categoryDTO) {
        categoryService.addCategory(categoryDTO);
        return Result.success();
    }
    @GetMapping("/list")
    @ApiOperation("获取分类名")
    public Result<List<Category>> findList(Integer type){
        List<Category> list = categoryService.findList(type);
        return Result.success(list);
    }
}
